package com.yvon.maple.service.msg.sub.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yvon.boot.mybatis.BaseServiceImpl;
import com.yvon.maple.constants.SystemConstant;
import com.yvon.maple.service.msg.sub.mapper.SubscribePassiveMapper;
import com.yvon.maple.service.msg.sub.model.entity.SubscribePassive;
import com.yvon.maple.service.msg.sub.service.SubscribePassiveService;
import org.springframework.stereotype.Service;
import java.util.List;

import static com.yvon.maple.constants.SystemConstant.Common.LIMIT_ONE;

/**
 * @author : Yvon
 * @since : 2022-05-19
 */
@Service
public class SubscribePassiveServiceImpl extends BaseServiceImpl<SubscribePassive, SubscribePassiveMapper> implements SubscribePassiveService {

    @Override
    public Boolean updateList(List<SubscribePassive> passiveList) {
        if (null == passiveList) {
            return false;
        }
        if (CollUtil.isNotEmpty(passiveList)) {
            remove(new QueryWrapper<>());
            return saveBatch(passiveList);
        }
        return false;
    }

    @Override
    public SubscribePassive getBySubscribeId(Long subscribeId) {
        return lambdaQuery()
                .eq(SubscribePassive::getSubscribeId, subscribeId)
                .last(LIMIT_ONE)
                .one();
    }
}
